package it.nola.soccer;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

public abstract class AbstractSoccerActivity extends Activity {
    protected DbHelper dbHelper=null;
    protected long cronaca;
    protected CharSequence team1Name;
    protected CharSequence team2Name;

    public abstract void cancella(View view);

    public void chiudi(View view) {
	finish();
    }

    protected abstract void fillData();

    public long getCronaca() {
	return cronaca;
    }

    public DbHelper getDbHelper() {
	return dbHelper;
    }

    public CharSequence getTeam1Name() {
	return team1Name;
    }

    public CharSequence getTeam2Name() {
	return team2Name;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	// recupera i parametri passati tramite Intent
	Bundle extras=getIntent().getExtras();
	extras.keySet();
	if (extras!=null) {
	    cronaca=extras.getLong(Const.Players.KEY_CRONACA);
	    team1Name=extras.getCharSequence(Const.HOME_TEAM.toString());
	    team2Name=extras.getCharSequence(Const.FOREIGN_TEAM.toString());
	}
	if (dbHelper==null) {
	    dbHelper=new DbHelper(this);
	    dbHelper.open();
	}
	performSetTitle();
	performSetContentView();
	prepareFields();
	fillData();
    }

    /**
     * effettua il settaggio dellla content view (demandato ai figli)
     */
    protected abstract void performSetContentView();

    /**
     * effettua il settaggio del titolo (demandato ai figli)
     */
    protected abstract void performSetTitle();

    /**
     * Inizializza i campi presenti nella View
     */
    abstract protected void prepareFields();

    /**
     * resetta i campi presenti nella view
     */
    abstract protected void resetField();

    public void salva(View view) {
	saveState();
	resetField();
	fillData();
    }

    abstract protected void saveState();
}
